﻿using CPPEI.Coolzon.Common;
using CPPEI.Coolzon.Server.CacheData;
using CPPEI.Coolzon.Service;
using CPPEI.Coolzon.Service.Contract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.Server.ServiceImplement
{
    /// <summary>
    /// 加载完毕时客户端会通知服务端程序，这个时候服务端程序需要修改客户端的状态
    /// EnteringDomain -> SynchronizeViewState
    /// </summary>
    class ReqLoadingFinishedHandler : BaseHandler<ReqLoadingFinishedData, RespLoadingFinishedData>
    {
        public ReqLoadingFinishedHandler()
            : base(RESPONSE_SCENARIO.SOLUTION, RESPONSE_COMMAND.SOLUTION.LOADINGFINISHED)
        {
        }

        protected override RespLoadingFinishedData OnHandle(Data.MainServiceData.Request request, ReqLoadingFinishedData requestData)
        {
            ControlDomain domain = CacheData.ServerData.Instance.GetDomain(request.Header.DomainId);
            Client client = CacheData.ServerData.Instance.GetClient(request.Header.UserIdentity);
            if (domain != null && client != null)
            {
                if(client.State == ClientState.EnteringDomain)
                {
                    client.State = ClientState.InDomain;
                }
            }
            return new RespLoadingFinishedData();
        }
    }
}
